<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//理财平台表
class Reload_log_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'reload_log';
    }
    function get_count($where){
        $this->db->select("*");
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->group_by('request_ip');
        return $this->db->get()->num_rows();
    }
    function get_list($where,$page,$limit){
        $this->db->select("*,".$this->plat_baseinfo_table.".company_bg_type");
        $this->db->from($this->table);
        $this->db->join($this->plat_baseinfo_table,  $this->table.".name_en = ".$this->plat_baseinfo_table.".plat_en" ,"left");
        $this->db->where($where);
        $this->db->order_by('sort','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_plat($where){
        $this->db->select($this->table.'.*');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by("create_time","desc");
        $query = $this->db->get();
        return $query->row_array(); 
    }
    //获取平台预付款
    function get_plat_payamount($where){
        $this->db->select($this->table.'.pay_amount');
        $this->db->from($this->table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();;
    }
    
    function get_info($where){
        $this->db->select($this->table.'.*,'.$this->plat_info.'.plat_en,'.$this->plat_info.'.description,'.$this->plat_info.'.banner_img,'.$this->plat_info.".banner_img_index,".$this->plat_info.'.banner_link,'.$this->plat_info.'.exper_time,'.$this->plat_info.'.update_time,'.$this->plat_info.'.receive_type,'.$this->plat_info.'.require,'.$this->plat_info.'.raiders');
        $this->db->from($this->table);
        $this->db->join($this->plat_info, $this->plat_info.'.plat_en = '.$this->table.'.name_en', 'left');
        $this->db->where($where);
        $this->db->order_by("plat.create_time", "desc");
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_baseinfo($where){
        $this->db->select($this->plat_baseinfo_table.'.*');
        $this->db->from($this->plat_baseinfo_table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();
    }
    function get_award_list($where){
        $this->db->select($this->plat_award_list.'.*');
        $this->db->from($this->plat_award_list);
        $this->db->where($where);
        $this->db->order_by("create_time", "asc");
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function check_ab_cpa($where){
        $this->db->select($this->plat_ab_cpa.'.*');
        $this->db->from($this->plat_ab_cpa);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_rules($where){
        $this->db->select("*");
        $this->db->from($this->plat_rule);
        $this->db->where($where);
        $this->db->order_by('step','asc');
        return $this->db->get()->result_array();
    }
    
    function get_interface($where){
        $this->db->select($this->plat_interface.'.*');
        $this->db->from($this->plat_interface);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_plat_invest($where){
        $this->db->select($this->plat_invest_list.'.*');
        $this->db->from($this->plat_invest_list);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_user_cpa_count($where){
        $this->db->select($this->plat_ab_cpa.'.*');
        $this->db->from($this->plat_ab_cpa);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->num_rows(); 
    }
    
    function get_user_cpa_info($where,$page,$limit){
        $this->db->select($this->plat_ab_cpa.'.*');
        $this->db->from($this->plat_ab_cpa);
        $this->db->where($where);
        $this->db->order_by('reg_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function insert_ab_cpa($data){
        $this->db->insert($this->plat_ab_cpa, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_plat($data,$id){
        return $this->db->where('id',$id)->update($this->table, $data);
    }
    function insert_ac_cpa($data){
        $this->db->insert($this->plat_ac_cpa, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function insert_plat_invest_list($data){
        $this->db->insert($this->plat_invest_list, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function insert_plat_log($data){
        $this->db->insert($this->plat_log, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_ab_cpa($data,$id){
        return $this->db->where('id',$id)->update($this->plat_ab_cpa, $data);
    }
    
    //我的推荐项目
    function recommend_plat_list($user_id){
        $sql = "SELECT tan_plat.*,tan_plat_baseinfo.company_bg_type FROM tan_plat
                LEFT JOIN tan_plat_baseinfo
                ON tan_plat_baseinfo.plat_en = tan_plat.name_en
                WHERE tan_plat.is_show = 1 AND tan_plat.is_fast_reg=1 AND tan_plat.id not IN (SELECT plat_id FROM tan_plat_ab_cpa WHERE user_id = ".$user_id." AND is_finish = 1)
                ORDER BY tan_plat.create_time LIMIT 0,3";
        return $this->db->query($sql)->result_array();
    }
    
    //个人中心-试玩列表
    function exper_plat_count($where){
        $this->db->select("*");
        $this->db->from($this->plat_info);
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        return $this->db->get()->num_rows();
    }
    
    function exper_plat_list($where,$page,$limit){
        $this->db->select($this->plat_info.'.plat_en name_en,'.$this->plat_ab_cpa.".*");
        $this->db->from($this->plat_info);
        $this->db->join($this->plat_ab_cpa,$this->plat_ab_cpa.".plat_en = ".$this->plat_info.".plat_en and tan_plat_ab_cpa.user_id = ".$this->userinfo['user_id'],"left");
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
}
